// ==== 定义块相关函数 ====
function saveModelDefinition() {
    const formTitle = document.getElementById('formTitle').value;
    const dataSourceUrl = document.getElementById('dataSourceUrl').value;
    const formRemark = document.getElementById('formRemark').value;
    const formCreator = document.getElementById('formCreator').value;
    const dataTableName = document.getElementById('dataTableName').value;
    const pageWidth = document.getElementById('pageWidth').value;
    const pageHeight = document.getElementById('pageHeight').value;
    const modelFieldsText = document.getElementById('modelFields').value;

    // 解析字段定义 - 逗号分隔的字符串
    const fields = [];
    if (modelFieldsText) {
        const fieldNames = modelFieldsText.split(',');
        fieldNames.forEach(fieldName => {
            const trimmedName = fieldName.trim();
            if (trimmedName) {
                fields.push(trimmedName);
            }
        });
    }

    // 更新formConfig中的metadata
    formConfig.metadata.title = formTitle;
    formConfig.metadata.dataSourceUrl = dataSourceUrl;
    formConfig.metadata.remark = formRemark;
    formConfig.metadata.creator = formCreator;
    formConfig.metadata.dataTableName = dataTableName;
    formConfig.metadata.pageWidth = pageWidth;
    formConfig.metadata.pageHeight = pageHeight;
    formConfig.metadata.fields = fields;

    // 更新JSON预览
    updateJsonPreview();

    alert('表单定义已保存');
}
// 初始化定义块
function initializeDefinitionBlock() {
    // 从formConfig中加载Model定义
    // 从formConfig中加载Model定义
    if (formConfig.metadata.title) {
        document.getElementById('formTitle').value = formConfig.metadata.title;
    }
    if (formConfig.metadata.dataSourceUrl) {
        document.getElementById('dataSourceUrl').value = formConfig.metadata.dataSourceUrl;
    }
    if (formConfig.metadata.remark) {
        document.getElementById('formRemark').value = formConfig.metadata.remark;
    }
    if (formConfig.metadata.creator) {
        document.getElementById('formCreator').value = formConfig.metadata.creator;
    }
    if (formConfig.metadata.dataTableName) {
        document.getElementById('dataTableName').value = formConfig.metadata.dataTableName;
    }
    if (formConfig.metadata.pageWidth) {
        document.getElementById('pageWidth').value = formConfig.metadata.pageWidth;
    }
    if (formConfig.metadata.pageHeight) {
        document.getElementById('pageHeight').value = formConfig.metadata.pageHeight;   
    }

    // 从formConfig中加载字段定义 - 逗号分隔
    if (formConfig.metadata.fields && formConfig.metadata.fields.length > 0) {
        document.getElementById('modelFields').value = formConfig.metadata.fields.join(', ');
    }
}
